﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include "IStructureWall.h"
#include "NdbObjectSchematic.h"
#include "IExternalData.h"
#include "RegenDataId.h"
#include "NdbDataSchema.h"
#include "RegenDataSchema.h"

namespace gcmp
{
    struct StructureWallInput;
    class IInstance;
    class StructureWall;
    class IParameter;

    class StructureWall : public NdbObjectSchematic, public IStructureWall
    {
        DATA_BEGIN(gcmp, StructureWall, gcmp::NdbObjectSchematic, DD54BA58 - C445 - 49D3 - B760 - 86084616BAE6, gmstructure)
            DATA_TRANSIENT(IElement*, pOwnerElement)
            DATA(ConcreteStrengthGradeType, ConcreteStrengthGrade)
            DATA_REGEN(double, Volume)
            DATA_REGEN(double, Length)
            DATA_REGEN(double, Area)
            DATA(Bool, WallShapeChanged)  //连接墙的厚度变化与洞口厚度变化
        DATA_END
        DECLARE_GETRDID_OVERRIDE_REGEN_FUNCTIONS(WallShapeChanged)

    public:
        static OwnerPtr<StructureWall> Create(IInstance* pInstance, const StructureWallInput* pInput);

        DECLARE_STRUCTURE_INSTANCE_METHODS;

        virtual double GetLength() const override { return GetLength__(); };
        bool SetLength(double length) { SetLength__(length); return true; };
        virtual double GetVolume() const override { return GetVolume__(); };
        bool SetVolume(double volume) { SetVolume__(volume); return true; };
        virtual double GetArea() const override { return GetArea__(); };
        bool SetArea(double area) { SetArea__(area); return true; };

        void SetWallShapeChanged(bool value) { SetWallShapeChanged__(value); MarkWallShapeChangedRdId(); }

    public:
        bool SetOwnerElement(IElement* pOwnerElement) { m_pOwnerElement = pOwnerElement; return true; }
        IElement* GetOwnerElement() { return m_pOwnerElement; }
        const IElement* GetOwnerElement() const { return m_pOwnerElement; }
        IDocument* GetDocument() const;
        ElementId GetOwnerElementId() const;
        virtual NdbObject* GetTopOwnerObject() const override;

    public:
        void UpdateForWeakParentDeletion(const std::set<ElementId>& deletedElementIds);
        void ReportParents(IElementParentReporter& reporter) const;
        void GetCalculators(ICalculatorCollection* calculators) const;

        void ReportParameterDefinitions(std::vector<int>* pParamDefIds) const;
        OwnerPtr<IParameter> GetNativeParameter(int paramDefId) const;
        bool SetNativeParameter(const IParameter *param, std::wstring* errorMsg = nullptr);
        bool IsParameterModifiable(int paramDefId) const;

        void Report(const gcmp::ICopyContext & copyContext, gcmp::ICopyStrategyReporter& reporter) const;
    };
}
